<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>垂直水平居中</title>
    <style>
        *{
            margin: 0;
            padding: 0;
        }
        html,body{
            height: 100%;
            width: 100%;
        }
        .bigbox{
            width: 100%;
            height: 100%;
            background: rgb(170, 70, 70);
        }
        .box{
            width: 300px;
            height: 300px;
            background-color: darkgreen;
        }
        /* 第一种 */
        /* .box{
            position: absolute;
            top: 0;
            left: 0;
            bottom: 0;
            right: 0;
            margin: auto;
        } */

        /* 第二种 */

        /* .box{
            position: absolute;
            top: 50%;
            left: 50%;
            transform: translate(-50%,-50%)
        } */

        /* 第三种 */

        .box{
            position: absolute;
            top: 50%;
            left: 50%;
            margin-top: -150px;
            margin-left: -150px;
        }
    </style>
</head>
<body>
    <div class="bigbox">
        <div class="box"></div>
    </div>
</body>
</html>